﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using weclever.Pages;

namespace weclever
{
    using weclever.Navigation;
    using weclever.Infrastructure;
    class Program
    {
        static void Main(string[] args)
        {
            MainPage page = new MainPage(WebConnectionFactory.GetNewWebClient());
            Console.WriteLine("Main page loaded");
            List<City> Cities = page.Cities();
            Console.WriteLine(string.Format("Number of cities: {0}", Cities.Count.ToString()));

            //IPageCommunication pc = new WebClientNavigation();
            //http://www.weclever.ru//
            //http://www.weclever.ru/moscow/korabl

  //          CityPositionPage cityPos = new CityPositionPage(WebConnectionFactory.GetNewWebClient(), new City() { NameEng = "moscow", NameRu = "Москва" }, "korabl");
//            cityPos.ExtractInfo();


            foreach (var c in Cities)
            {
                Console.WriteLine(string.Format("{0} started", c.NameEng));
                CityPage cp = new CityPage(WebConnectionFactory.WebClient, c);
                List<string> links = cp.PositionLinks();
                Console.WriteLine(string.Format("City {0} has {1} positions", c.NameEng, links.Count));
                foreach (var s in links)
                {
                    CityPositionPage cpp = new CityPositionPage(WebConnectionFactory.GetNewWebClient(), c, s);
                    PageInfo pi = cpp.ExtractInfo();
                    pi.WriteToFile(SiteUrls.DataDirectory);
                    Console.WriteLine(string.Format("{0} position saved", s));
                }
                /*
                using (StreamWriter sw = new StreamWriter(String.Format("{0}.html", c.NameEng)))
                {
                    sw.Write(cp.SiteHtml);
                }
                 */
            }


            //sw.Write(pc.NavigateToURL("http://www.weclever.ru"));
            Console.WriteLine("done");
        }
    }
}
